/**
 * 用户注册判断js
 */
    /*
     实时判断用户名是否合法
    */
    function checkUserName() {
    var input = new RegExp(/^[\s]*$/);
    var userName = document.getElementById("userName").value;
    var matchResult = true;
    if (userName == "" ) {
        alert("姓名不能为空！");
        matchResult = false;
    }else if(input.test(userName)){
        alert("不能为空格！");
        matchResult = false;
    } else if (userName.length < 6 || userName.length > 20) {
        alert("用户名长度应在6到20个字符之间！");
        matchResult = false;
    }
    }
    /*
        实时判断密码是否合法
     */
    function checkPassword() {
        var input = new RegExp(/^[\s]*$/);
    var password = document.getElementById("password").value;
    var matchResult = true;
    if (password == "" ) {
        alert("密码不能为空");
        matchResult = false;
    }else if(input.test(password)){
        alert("密码不能为空格！");
        matchResult = false;
    }
    }

    /*
    实时判断重复输入密码是否合法
     */
    function checkRePassword() {
    var input = new RegExp(/^[\s]*$/);
    var rePassword = document.getElementById("rePassword").value;
    var matchResult = true;
    if ( rePassword == "") {
        alert("请输入重复密码");
        matchResult = false;
    }else if(input.test(rePassword)){
        alert("密码不能为空格！");
        matchResult = false;
    }
}
    /*
        判断用户提交数据是否合法
     */
    function login(form) {
        var password = document.getElementById("password").value;
        var userName = document.getElementById("userName").value;
        var rePassword = document.getElementById("rePassword").value;
        var sex = document.getElementsByName("sex");
        var hobby = document.getElementsByName("hobby[]");
        var text = document.getElementById("content").value;
        var photo = document.getElementById("photo").value;
        var input = new RegExp(/[^\w$] /);
        var matchResult = true;
        if (userName == "" ) {
            alert("姓名不能为空！");
            form.pass.focus();
            matchResult = false;
        }
        if(input.test(userName)){
            alert("用户名非法，只能为字母数字和下划线！");
            form.pass.focus();
            matchResult = false;
        }
        if (userName.length < 6 || userName.length > 20) {
            alert("用户名长度应在6到20个字符之间！");
            form.pass.focus();
            matchResult = false;
        }
        if (password == "" || rePassword == "") {
            alert("密码不能为空");
            form.pass.focus();
            matchResult = false;
        }

        if(userName==password||userName==rePassword){
            alert("密码或重复密码不能和用户名相同！");
            form.pass.focus();
            matchResult=false;
        }
        if(password!=rePassword){
            alert("密码和重复密码不同，请重新输入！");
            form.pass.focus();
            matchResult=false;
        }
        if(input.test(rePassword)){
            alert("密码不能为空格！");
            matchResult = false;
        }
        if(userName.length<6||userName.length>20){
            alert("用户名长度应在6到20个字符之间！");
            form.pass.focus();
            matchResult=false;
        }
        var hobbyNum=0;
        for(var i=0;i<hobby.length;i++){
            if(hobby[i].checked){//check是否选中
                hobbyNum+=1;
            }
        }
        if(hobbyNum == 0){
            alert("爱好不能为空");
            form.pass.focus();
            matchResult=false;
        }
        if(photo==""){
            alert("文件不能为空");
            form.pass.focus();
            matchResult=false;
        }
        if(text==""){
            alert("个人简介不能为空");
            form.pass.focus();
            matchResult=false;
        }
        return matchResult;
}

